# author: alex
# time: 2022/4/29 20:21
import ddt
import pandas as pd
import unittest

import requests


def readFile():
    file = pd.read_csv('data/login_data.csv')
    df = pd.DataFrame(file).fillna('')
    da=df.to_dict(orient='records')
    return da

@ddt.ddt
class Login_interface_test(unittest.TestCase):

    def setUp(self) -> None:
        self.url='http://127.0.0.1:8081/user/login'

    @ddt.data(*readFile())
    def test_login(self,data):
        dic={
            'phonenumber':data.get('username'),
            'password':data.get('password')
        }
        res = requests.post(self.url, data=dic)
        print(res.status_code)
        if data.get('state')==1:
            self.assertEqual(res.status_code,200)
        else:
            self.assertNotEqual(res.status_code,200)


    def tearDown(self) -> None:
        pass

if __name__=='__main__':
    unittest.main()